package com.xhl.consul.tool.config;

import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.environment.EnvironmentChangeEvent;
import org.springframework.cloud.context.refresh.ContextRefresher;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;

import java.util.Set;

/**
 * @Author CazCen
 * @Date 2021/11/23 21:40
 */
@Component
public class ApolloConfig implements ApplicationContextAware {


    private final static Logger logger =  LoggerFactory.getLogger(ApolloConfig.class);

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;

    }

    /**
     * 监听apollo路由修改
     * 修改apollo信息会触发这里
     * @param changeEvent
     */
    @ApolloConfigChangeListener(value = "application")
    public void onChange(ConfigChangeEvent changeEvent) {

        // 获取环境上下文信息,修改之前的信息

        logger.info("changeEvent :{}",changeEvent.changedKeys());

    }




}
